<?
class exportText{
 var $type;
 var $sql;
  function exportText($type){
  $this->type = $type;
  /*mysql_connect("localhost","root") or die("could not connection");
  mysql_select_db("yellowpages");*/
  mysql_connect("localhost","ypvnjsc_ypvn","yp2006") or die("could not connection");
  mysql_select_db("ypvnjsc_yellowpages");
 }
  function setsql(){
  $a = func_get_args(); $lm='';
  switch($a[0]){
   case 'main':
    $this->sql="select class_name_us, id_class.class_id_1,class_name_vn, town_name_us, prefix 
			from class,id_class,town, company_name, company, company_notes, no_tel
			where company.company_id=company_name.idall and company.company_id=company_notes.company_id 
			and company.company_id=no_tel.idall and company.town_id=town.town_id 
			and  and sort_no=1";
    break;
   case 'mainbrd':
      $this->sql="SELECT town_name_us,prefix,trade_name,company_us,company_vn,company_name.idall
			   	FROM company_name,town,id_trade,trade_name
			   	WHERE company_name.town_id=town.town_id
			   	and company_name.idall=id_trade.company_id
				and id_trade.trade_name_1=trade_name.trade_id
				order by town_name_us,trade_name,company_us
				";
    break;
   case "maincls":
//    if(isset($a[2])) $lm="limit 0,500";
    $this->sql="SELECT town_name_$a[1],prefix,company_$a[1],company_name.idall
			   	FROM company_name,town
			   	WHERE company_name.town_id=town.town_id
				order by town_name_$a[1],company_$a[1]
				";
	break;
   case 'class':
    $this->sql="SELECT class_id_1 FROM id_class where company_id=$a[1] order by sort_no";
    break;
  }
 }
 function showBrandName(){
  $a = func_get_args(); $flag='';
  $this->setsql($this->type);
  $result=mysql_query($this->sql) or die('could not query');
  while($rs=mysql_fetch_array($result,MYSQL_NUM)){
   if($flag!=$rs[0]){
    echo("$rs[0] (Area Code - $rs[1])\r\n\r\n\r\n");
	$flag=$rs[0];
   }
   $t="$rs[2]\r\n$rs[3]\r\n$rs[4]\t".$this->getIdClass('class',$rs[5])."\r\n";
   echo($t);
  }
  mysql_free_result($result);
 }
  function companyList($lang){// town_name_us,prefix,company_us,company_name.idall
  $this->setsql($this->type,$lang); $flag='';
  $result=mysql_query($this->sql) or die('could not query');
  /*echo(mysql_num_rows($result));
  mysql_free_result($result);
  $result=mysql_query($this->sql)*/
   while($rs=mysql_fetch_array($result)){
   if($flag!=$rs[0]){
    echo("$rs[0] (Area Code - $rs[1])\r\n\r\n\r\n");
	$flag=$rs[0];
   }
   $t="$rs[2]\t".$this->getIdClass('class',$rs[3])."\r\n";
   echo($t);
  }
  mysql_free_result($result);
 }
  function getIdClass(){
  $a = func_get_args();
  $this->setsql($a[0],$a[1]); //echo($this->sql);
  $result = mysql_query($this->sql) or die('counld not query class');
  $t='';
  while($rs=mysql_fetch_array($result,MYSQL_NUM)){
   if(strlen($rs[0])==5) $rs[0]="0$rs[0]";
   $t.="$rs[0], ";
  }
  return substr($t,0,strlen(trim($t))-1);
 }
}//end class
?>